package com.cike.ssm.utils;

import java.io.File;
import java.io.FileOutputStream;
import java.util.List;

import org.apache.poi.ss.usermodel.Workbook;
import org.jeecgframework.poi.excel.ExcelExportUtil;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.entity.enmus.ExcelType;

public class ExcelUtil {
	/**
	 * 导出
	 * 
	 * @param exports
	 *            导出数据
	 * @param table
	 *            导出名称
	 * @throws Exception
	 */
	public static void exportExcel(List<ExportEntity> exports, String table) throws Exception {
		ExportParams params = new ExportParams(null, null, ExcelType.XSSF);
		Workbook workbook = ExcelExportUtil.exportExcel(params, ExportEntity.class, exports);
		FileOutputStream fos = new FileOutputStream("D:/" + table + ".xlsx");
		workbook.write(fos);
		fos.close();
	}
	/**
	 * 导入
	 * @param filePath
	 * @return
	 */
	public static List<ExportEntity> importExcel(String filePath) {
		ImportParams params = new ImportParams();
		List<ExportEntity> list = ExcelImportUtil.importExcel(new File(filePath), ExportEntity.class, params);
		return list;
	}
}
